<%@ include file="../common.jsp"%>

<script type="text/javascript">
$(document).ready(
		function() {
			$("#locationForm").attr("action",'<c:url value="/saveBusinessUnitNewDetails.htm"></c:url>');
			
		});
</script>


<div>
	<c:choose>
		<c:when test="${size > 0}">
			<form name="editBusinessUnitDetails" id="editBusinessUnitDetails">
				<div style="width: 70%;">
					<table class="viewDetails">
						<tr class="adminTableMainHeaderColor tableChildHeaderFont">
							<th colspan="6" align="center"> <span class="searchResultsCaption"> LIST OF BUISNESS UNIT(S) </span> </th>
						</tr>
						<tr class="heading">
							<th> Select </th>
							<th> Name </th>
							<th> Code </th>
							<th> Company </th>
							<th> Type </th>
							<th> Department(s) </th>
						</tr>	
					
					<c:forEach items="${locationMap}" var="locationMap" varStatus="loop">
						<c:set var="tabColor" value="odd"></c:set>
					     	<c:if test="${(loop.index % 2) eq 0}">
					        	<c:set var="tabColor" value="even"></c:set>
					        </c:if>
					         
						<tr class="${tabColor}">
							<td align="center"> 
								<input type="radio" id="radio${index.index}" name="radio" value="${locationMap.value.ldId}"/> 
							</td>
							<td> ${locationMap.value.ldName} </td>
							<td> ${locationMap.value.ldCode} </td>
							<td> ${locationMap.value.ldCompanyId.cdName} </td>
							<td> ${locationMap.value.ldType} </td>
							<td> <c:forEach items="${locationMap.value.departmentDetailsDTOs}" var="department">
									${department.ddName}<br>
								 </c:forEach> 
							</td>
						</tr>
					</c:forEach>
				</table>
				<table>
					<tr align="left">
						<td colspan="5">
							<input class="formButton ui-corner-all" type="button" value="SELECT" onclick="submitBusinessUnitDetailsToEdit();" />
						</td>
					</tr>
				</table>
			</div>
			
				
					
			</form>
			
			<c:if test="${resultOfSave}">
				Operation Done Successfully.
			</c:if>
	
			<br>
			<hr/>
			<br>
	
				<form:form commandName="locationForm" id="locationForm">
						<form:hidden path="ldId" id="locationId"/> 
<%-- 						<form:errors path="ldId" cssClass="errorMsg"/>  --%>
					<table class="adminFilterTable">
						<tr class="tableChildHeaderColor">
							<th colspan="5" align="center"> EDIT BUSINESS UNIT DETAILS </th> 
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr>
							<td class="spacingColumnWidthLess"></td>
							<td class="formLabel"> Name* </td>
							<td class="spacingColumnWidthLess"></td>	
							<td class="formField"> <form:input path="ldName" id="locationName"/> 
								<form:errors path="ldName" cssClass="errorMsg" /> </td>
							<td class="spacingColumnWidthLess"></td>
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr>
							<td class="spacingColumnWidthLess"></td>
							<td class="formLabel"> Code </td>
							<td class="spacingColumnWidthLess"></td>	
							<td class="formField"> <form:input path="ldCode" id="locationCode" readonly="true"/> 
								<form:errors path="ldCode" cssClass="errorMsg" /> </td>
							<td class="spacingColumnWidthLess"></td>
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr>
							<td class="spacingColumnWidthLess"></td>
							<td class="formLabel"> Company Name* </td>
							<td class="spacingColumnWidthLess"></td>	
							<td> <form:select path="ldCompanyId.cdId" id="companyName">
									 <form:option value="0">Choose Company</form:option>
									 <c:forEach var="companyList" items="${companyList}">
										<form:option value="${companyList.cdId}">${companyList.cdName}</form:option>
									 </c:forEach>
								 </form:select>
								 <form:errors path="ldCompanyId.cdId" cssClass="errorMsg" /> </td>
							<td class="spacingColumnWidthLess"></td>
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr>
							<td class="spacingColumnWidthLess"></td>
							<td class="formLabel"> Type*</td>
							<td class="spacingColumnWidthLess"></td>
							<td> <form:select path="ldType" id="loctionType">
									<form:option value="0">Choose Unit</form:option>
									<c:forEach var="bUList" items="${bUList}">
										<form:option value="${bUList.buTypeName}">${bUList.buTypeName}</form:option>
									</c:forEach>
								</form:select>
								<form:errors path="ldType" cssClass="errorMsg" /> </td>
							<td class="spacingColumnWidthLess"></td>
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr>
							<td class="spacingColumnWidthLess"></td>
							<td class="formLabel"> Department* </td>
							<td class="spacingColumnWidthLess"></td>
							<td class="formLabel">  
								<c:forEach var="departmentMap" items="${departmentMap}">
									<form:checkbox path="ddId" id="departmentMap" value="${departmentMap.key}" label="${departmentMap.value}"/>
								</c:forEach>
								<form:errors path="ddId" cssClass="errorMsg" /> </td>
							<td class="spacingColumnWidthLess"></td>
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
						<tr align="left">
							<td class="spacingColumnWidthLess"></td>
							<td></td>
							<td class="spacingColumnWidthLess"></td>
							<td colspan="2"> <input class="formButton ui-corner-all" type="button" value="UPDATE" onclick="javascript:addEntity('locationForm')"> </td>
						</tr>
						<tr class="formSpacingRow"><td></td> </tr>
					</table>
				</form:form>
			</c:when>
		<c:otherwise>
			No Records Found.
		</c:otherwise>
	</c:choose>
</div>